package org.brownflat.lighthouse.monitoring.ci.bamboo;

import org.brownflat.lighthouse.monitoring.ci.ConnectionException;
import org.brownflat.lighthouse.monitoring.ci.HTTPServer;
import org.brownflat.lighthouse.monitoring.ci.Monitorable;

public class BambooServer extends HTTPServer implements Monitorable {

    public BambooServer(String host, int port) {
        super(host, port);
    }

    @Override
    public boolean isCurrentlyBroken() {
        BambooLatestBuildsRequest request = new BambooLatestBuildsRequest();
        String response = null;
        try {
            response = execute(request);
        } catch (ConnectionException e) {
            throw new RuntimeException(e);
        }
        return response.contains("class=\"Failed\"");
    }

    @Override
    public String getName() {
        return "Bamboo";
    }
}
